package guda.mrpc.core.transport;


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.SocketAddress;

/**
 * Created by well on 17/5/23.
 */
public abstract class ServerHandler<T> extends ChannelInboundHandlerAdapter {

    public static final Logger log = LoggerFactory.getLogger(ServerHandler.class);

    protected SocketAddress remoteAddress;

    protected SocketAddress localAddress;

    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        super.channelRegistered(ctx);
        this.localAddress=ctx.channel().localAddress();
        remoteAddress=ctx.channel().remoteAddress();
    }



    public SocketAddress getRemoteAddress() {
        return remoteAddress;
    }

    public SocketAddress getLocalAddress() {
        return localAddress;
    }


    public abstract void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception;
}
